﻿using System;
using Microsoft.Extensions.ObjectPool;

namespace CardGameCore.Battle
{
    public abstract class BaseResult<T> where T : BaseResult<T>, IDisposable, new()
    {
        private const int MaximumRetained = 3;

        public static ObjectPool<T> Pool { get; } =
            new DefaultObjectPool<T>(new DefaultPooledObjectPolicy<T>(), MaximumRetained);

        public virtual void Dispose()
        {
            OnDispose();
            Pool.Return(this as T);
        }

        protected virtual void OnDispose() { }
    }
}